# !/usr/bin/env python
# !-*-coding:utf-8 -*-
# !@TIME: 
# !@Author : Destroy丶寒露
# !@File :.py

import time

class FilmTop:

    def __init__(self, driver):
        self.driver = driver
        #self.data_subscript = 0
    # 获取每一页的信息
    def start(self, visitweb):
        dl = self.driver.find_element_by_class_name('board-wrapper')
        movie_list = dl.find_elements_by_tag_name('dd')
        for movie in movie_list:
            movie_url = movie.find_element_by_tag_name('a').get_attribute('href')
            movie_name = movie.find_element_by_tag_name('a').get_attribute('title')
            movie_score = movie.find_element_by_class_name('integer').text + movie.find_element_by_class_name(
                'fraction').text
            movie_time = movie.find_element_by_class_name('releasetime').text
            #print("No.%d: %s" % (visitweb.data_num, movie_name))
            movie_info_list = {'1_No': '', '2_name': '', '3_link': '', '4_releasetime': '', '5_score': ''}
            info = [visitweb.data_num, movie_name, movie_url, movie_time, movie_score]  # str(visitweb.data_num)
            movie_info_list = dict(zip(movie_info_list.keys(), info))
            visitweb.data_num += 1
            visitweb.info_list.append(movie_info_list)
        try:
            self.next_page(visitweb)  # 翻页
        except Exception as e:
            print('已到末页！')

    # 翻页
    def next_page(self, visitweb):
        next_btn = self.driver.find_element_by_partial_link_text("下一页")
        next_btn.click()
        time.sleep(3)
        self.start(visitweb)

